var express = require('express')
var router = express.Router()
const { verifyAccessToken } = require('./middlewares/auth')

// 使用 dart-sass 在服务端编译 SCSS
const sass = require('sass')

// POST /api/scss/compile
router.post('/scss/compile', verifyAccessToken, async function (req, res) {
  const scss = req.body?.scss ?? ''
  const style = req.body?.style === 'compressed' ? 'compressed' : 'expanded'
  try {
    const result = sass.compileString(scss, { style })
    return res.json({ css: result.css })
  } catch (err) {
    return res.status(400).json({ message: err.message || 'SCSS 编译失败' })
  }
})

module.exports = router